// pages/qrcode/index.js
import QRcode from "../dist/weapp.qrcode.esm"
// const app =getApp()
Page({
  data:{
    text:'你好呀，QR-Code',
    scan:''
  },
  onLoad(){
  this.test()
  this.setData({
    "text":''
  })
  },
  test(){
    QRcode({
      width: 200,
      height: 200,
      canvasId: 'myQrcode',
      text: this.data.text,
      image: {
        imageResource: '../img/profile.jpg',
        dx: 70,
        dy: 70,
        dWidth: 60,
        dHeight: 60
      }
    }),
    this.setData({
      "text":''
    })
  },
  scanQRcode(){
    const self = this
    // 小程序菜单操作
    wx.showActionSheet({
      itemList: ['扫描二维码', '生成二维码'],
      itemColor: 'rgb(201, 80, 44)',
      success (res) {
        switch (res.tapIndex) {
          case 0:
            // 微信小程序扫描二维码功能
            wx.scanCode({
              success (res) {
                // const result =res.scan
                // app.global.scanCodeData=res.result
                self.setData({
                  scan:res.result
                })
                wx.navigateTo({
                  url: `/pages/qrcodeSacn/index?title=${self.data.scan}` //res.result.scan
                })
              },
              fail(res) {
                console.log(res)
              }
            })
            break
          case 1:
            wx.navigateTo({
              url: "/pages/qrcode/index"
            })
            break
        }
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  }

})